<template>
  <el-dialog :visible.sync="visible" width="70%" :title="!dataForm.id ? $t('add') : $t('update')" :close-on-click-modal="false" :close-on-press-escape="false">
    <el-col :span="24">
      <el-form v-loading="loading" :model="dataForm"  ref="dataForm" :label-width="$i18n.locale === 'en-US' ? '120px' : '120px'">
        <el-col :span="8">
          <!-- 应用ID -->
          <el-form-item label="接口编码" prop="apiCode">
            <!--文本框-->
            <el-input v-model="dataForm.apiCode" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <!-- 接口api method -->
          <el-form-item label="接口名称" prop="apiName">
            <!--文本框-->
            <el-input v-model="dataForm.apiName" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <!-- 接口请求签名 -->
          <el-form-item label="请求签名" prop="apiSign">
            <!--文本框-->
            <el-input v-model="dataForm.apiSign" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <!-- 接口请求时间 -->
          <el-form-item label="请求开始时间" prop="apiReqTime">
            <!--日期框-->
            <el-input v-model="dataForm.apiReqTime" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <!-- 接口请求时间 -->
          <el-form-item label="请求结束时间" prop="apiRspTime">
            <!--日期框-->
            <el-input v-model="dataForm.apiRspTime" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <!-- 接口请求时间 -->
          <el-form-item label="请求耗时(ms)" prop="apiDuration">
            <!--日期框-->
            <el-input v-model="dataForm.apiDuration" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <!-- 接口请求URL参数 -->
          <el-form-item label="请求URL参数" prop="apiUrlParams">
            <!--文本框-->
            <el-input v-model="dataForm.apiUrlParams" type="textarea" :rows="2" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <!-- 接口请求body参数体 -->
          <el-form-item label="请求参数体" prop="reqBodyStr">
            <!--文本框-->
            <el-input v-model="dataForm.reqBodyStr" type="textarea" :rows="8" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <!-- 接口响应报文 -->
          <el-form-item label="响应报文" prop="respStr">
            <!--文本框-->
            <el-input v-model="dataForm.respStr" type="textarea" :rows="8" disabled></el-input>
          </el-form-item>
        </el-col>
      </el-form>
    </el-col>
    <template slot="footer">
      <el-button @click="visible = false">{{ $t('close') }}</el-button>
    </template>
  </el-dialog>
</template>
<script>
export default {
  data () {
    return {
      loading: false,
      visible: false,
      dataForm: {
        id: '',
        apiCode: '',
        apiDuration: '',
        apiName: '',
        apiReqTime: '',
        apiRspTime: '',
        apiSign: '',
        apiStatus: '',
        apiUrlParams: '',
        reqBodyStr: '',
        respStr: ''
      }
    }
  },
  methods: {
    init () {
      this.visible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].resetFields()
        if (this.dataForm.id) {
          this.loading = true
          this.getInfo()
        }
      })
    },
    // 获取信息
    getInfo () {
      this.$http.get(`/api/apiLog/${this.dataForm.id}`).then(({ data: res }) => {
        this.loading = false
        if (res.code !== 0) {
          return false
        }
        this.dataForm = {
          ...this.dataForm,
          ...res.data
        }
      }).catch(() => {})
    }
  }
}
</script>
